<template>
  <el-dialog
    title="用户详情"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户名" prop="userName">
      <el-input :value="dataForm.userName" placeholder="用户名"></el-input>
    </el-form-item>
    <el-form-item label="手机号码" prop="phoneNumber">
      <el-input :value="dataForm.phoneNumber" placeholder="手机号码"></el-input>
    </el-form-item>
    <!-- <el-form-item label="密码" prop="password">
      <el-input v-model="dataForm.password" placeholder="${column.comments}"></el-input>
    </el-form-item> -->
    <el-form-item label="真实姓名" prop="realName">
      <el-input :value="dataForm.realName" placeholder="真实姓名"></el-input>
    </el-form-item>
    <!-- <el-form-item label="证件类型" prop="cardType">
      <el-input v-model="dataForm.cardType" placeholder="${column.comments}"></el-input>
    </el-form-item> -->
    <el-form-item label="证件号" prop="cardId">
      <el-input :value="dataForm.cardId" placeholder="证件号"></el-input>
    </el-form-item>
    <el-form-item label="注册时间" prop="createTime">
      <el-input :value="dataForm.createTime" placeholder="注册时间"></el-input>
    </el-form-item>
    <el-form-item label="来源" prop="appId">
      <el-input :value="dataForm.appIdText" placeholder="来源"></el-input>
    </el-form-item>
    <!-- <el-form-item label="用户类型" prop="userType">
      <el-input v-model="dataForm.userType" placeholder="用户类型"></el-input>
    </el-form-item> -->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <!-- <el-button type="primary" @click="dataFormSubmit()">确定</el-button> -->
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          userName: '',
          phoneNumber: '',
          password: '',
          realName: '',
          cardType: '',
          cardId: '',
          createTime: '',
          updateTime: '',
          state: '',
          appId: '',
          appIdText: '',
          userType: '',
          departmentId: '',
          openId: '',
          otherId: ''
        },
        dataRule: {
          /*userName: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          phoneNumber: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          realName: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          cardType: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          cardId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          state: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          appId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          userType: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          departmentId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          openId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          otherId: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ]*/
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/authentication/authenticationuser/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userName = data.authenticationUser.userName
                this.dataForm.phoneNumber = data.authenticationUser.phoneNumber
                this.dataForm.password = data.authenticationUser.password
                this.dataForm.realName = data.authenticationUser.realName
                this.dataForm.cardType = data.authenticationUser.cardType
                this.dataForm.cardId = data.authenticationUser.cardId
                this.dataForm.createTime = data.authenticationUser.createTime
                this.dataForm.updateTime = data.authenticationUser.updateTime
                this.dataForm.state = data.authenticationUser.state
                this.dataForm.appId = data.authenticationUser.appId
                this.dataForm.appIdText = data.authenticationUser.appIdText
                this.dataForm.userType = data.authenticationUser.userType
                this.dataForm.departmentId = data.authenticationUser.departmentId
                this.dataForm.openId = data.authenticationUser.openId
                this.dataForm.otherId = data.authenticationUser.otherId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/authentication/authenticationuser/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'userName': this.dataForm.userName,
                'phoneNumber': this.dataForm.phoneNumber,
                'password': this.dataForm.password,
                'realName': this.dataForm.realName,
                'cardType': this.dataForm.cardType,
                'cardId': this.dataForm.cardId,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'state': this.dataForm.state,
                'appId': this.dataForm.appId,
                'userType': this.dataForm.userType,
                'departmentId': this.dataForm.departmentId,
                'openId': this.dataForm.openId,
                'otherId': this.dataForm.otherId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
